import { Component, OnInit, ViewChild } from '@angular/core';
import { STColumn, STComponent } from '@delon/abc/st';
import { SFComponent, SFSchema, SFUISchema } from '@delon/form';
import { ModalHelper, _HttpClient } from '@delon/theme';
import { BussinessStatisticsService } from '../../services/bussiness-statistics.service';

@Component({
  selector: 'app-partner-partner-custom-order-detail',
  templateUrl: './partner-custom-order-detail.component.html',
  styleUrls: ['./partner-custom-order-detail.component.less']
})
export class PartnerPartnerCustomOrderDetailComponent implements OnInit {
  schema: SFSchema = {};
  ui!: SFUISchema;
  detailInfo: any = {
    logo: './assets/images/user/logo.svg',
    company: '张三',
    code: '91440300357887492H',
    proxy: '企业合伙人',
    belongCity: '深圳、上海、北京',
    createTime: '2021-09-23 14:43:31'
  }
  @ViewChild('st') private readonly st!: STComponent;
  @ViewChild('sf') private readonly sf!: SFComponent;
  columns: STColumn[] = [];
  _$expand = false;

  constructor(public service: BussinessStatisticsService) {

  }

  get reqParams() {
    return { ...this.sf?.value };
  }

  ngOnInit(): void {
    this.initST();
    this.initSF();
  }

  resetSF() {
    this._$expand = false;
    this.sf.reset();
    setTimeout(() => {
      this.st.reset();
    })
  }
  /**
* 伸缩查询条件
*/
  expandToggle() {
    this._$expand = !this._$expand;
    this.sf?.setValue('/_$expand', this._$expand);
  }

  add(): void {
    // this.modal
    //   .createStatic(FormEditComponent, { i: { id: 0 } })
    //   .subscribe(() => this.st.reload());
  }
  search() {
    this.st.load(1);
  }
  export() {

  }

  initSF() {
    this.schema = {
      properties: {
        abnormalCause: {
          title: '订单号',
          type: 'string',
          ui: {
            placeholder: '请输入',
          },
        },
        abnormalCause1: {
          title: '订单状态',
          type: 'string',
          default: '',
          enum: [
            {
              label: '全部',
              value: ''
            },
            {
              label: '个人',
              value: '1'
            },
            {
              label: '企业',
              value: '2'
            }
          ],
          ui: {
            widget: 'select'
          },
        },
        abnormalCause2: {
          title: '开票状态',
          type: 'string',
          default: '',
          enum: [
            {
              label: '全部',
              value: ''
            },
            {
              label: '个人',
              value: '1'
            },
            {
              label: '企业',
              value: '2'
            }
          ],
          ui: {
            widget: 'select'
          },
        },
      }
    }
    this.ui = {
      '*': { spanLabelFixed: 100, grid: { span: 7, gutter: 4 } },
    };
  }
  /**
 * 初始化数据列表
 */
  initST() {
    this.columns = [
      { title: '订单号', index: 'carNo', className: 'text-center', width: 150 },
      { title: '订单状态', render: 'carModelLabel', className: 'text-center', width: 120 },
      { title: '订单金额（元）', index: 'carNo', className: 'text-center', width: 200 },
      { title: '实际付款金额（元）', render: 'approvalStatus0', className: 'text-center', sort: true, width: 150 },
      { title: '客户附加费率', render: 'approvalStatus', className: 'text-center', sort: true, width: 150 },
      { title: '预估收益（元）', render: 'approvalStatus1', className: 'text-center', sort: true, width: 120 },
      { title: '开票状态', render: 'approvalStatus2', className: 'text-center', sort: true, width: 180 },
      { title: '开票金额（元）', render: 'approvalStatus3', className: 'text-center', sort: true, width: 180 },
      { title: '下单时间', index: 'approvalStatus5', className: 'text-right', sort: true, type: 'currency', width: 180 },
      {
        title: '操作',
        width: 150,
        buttons: [
          {
            text: '查看订单详情',
            click: (_record) => this.viewOrderDetail(_record)
          }
        ]
      },
    ];
  }

  viewOrderDetail(record: any) {

  }
  goBack() {
    window.history.go(-1);
  }

}
